package com.ruoyi.system.service.impl;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.ruoyi.common.core.domain.entity.SysDictData;
import com.ruoyi.framework.web.service.DictService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.DutyInfoMapper;
import com.ruoyi.system.domain.DutyInfo;
import com.ruoyi.system.service.IDutyInfoService;
import com.ruoyi.common.core.text.Convert;

/**
 * 值日规划Service业务层处理
 * 
 * @author ruoyi
 * @date 2021-11-11
 */
@Service("DutyInfo")
public class DutyInfoServiceImpl implements IDutyInfoService 
{
    @Autowired
    private DutyInfoMapper dutyInfoMapper;

    @Autowired
    private DictService dictService;

    /**
     * 查询值日规划
     * 
     * @param id 值日规划主键
     * @return 值日规划
     */
    @Override
    public DutyInfo selectDutyInfoById(Long id)
    {
        return dutyInfoMapper.selectDutyInfoById(id);
    }

    /**
     * 查询值日规划列表
     * 
     * @param dutyInfo 值日规划
     * @return 值日规划
     */
    @Override
    public List<DutyInfo> selectDutyInfoList(DutyInfo dutyInfo)
    {
        return dutyInfoMapper.selectDutyInfoList(dutyInfo);
    }

    /**
     * 新增值日规划
     * 
     * @param dutyInfo 值日规划
     * @return 结果
     */
    @Override
    public int insertDutyInfo(DutyInfo dutyInfo)
    {
        return dutyInfoMapper.insertDutyInfo(dutyInfo);
    }

    /**
     * 修改值日规划
     * 
     * @param dutyInfo 值日规划
     * @return 结果
     */
    @Override
    public int updateDutyInfo(DutyInfo dutyInfo)
    {
        return dutyInfoMapper.updateDutyInfo(dutyInfo);
    }

    /**
     * 批量删除值日规划
     * 
     * @param ids 需要删除的值日规划主键
     * @return 结果
     */
    @Override
    public int deleteDutyInfoByIds(String ids)
    {
        return dutyInfoMapper.deleteDutyInfoByIds(Convert.toStrArray(ids));
    }

    @Override
    public int deleteDutyInfoByTimePidDay(DutyInfo dutyInfo) {
        return dutyInfoMapper.deleteDutyInfoByTimePidDay(dutyInfo);
    }

    @Override
    public int deleteDutyInfoByDay() throws ParseException {
        DutyInfo dutyInfo = new DutyInfo();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        dutyInfo.setDay(new Date(format.parse(format.format(new Date())).getTime() - 24 * 3600 * 1000));
        return dutyInfoMapper.deleteDutyInfoByDay(dutyInfo);
    }

    /**
     * 删除值日规划信息
     * 
     * @param id 值日规划主键
     * @return 结果
     */
    @Override
    public int deleteDutyInfoById(Long id)
    {
        return dutyInfoMapper.deleteDutyInfoById(id);
    }

    /**
     *往后预约天数
     * @return 返回预填充天数
     */
    public List<Date> getDateList(){
        List<Date> list = new ArrayList<>();
        int TimeInterval = 0;
        Date nowDate = new Date();
        for (SysDictData sysDictData:dictService.getType("apply_time")) {
            TimeInterval = Integer.parseInt(sysDictData.getDictValue());
        }
        for(int i=0;i<TimeInterval;i++){
            list.add(new Date(nowDate.getTime()+24 * 3600 * 1000*i));
        }
        return list;
    }
}
